﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace SmartCity.ProcessEngine.Infrastructure.Extensions
{
    /// <summary>
    /// 枚举扩展
    /// </summary>
    public static class EnumExtension
    {
        /// <summary>
        /// 获取枚举值的特性的值
        /// </summary>
        /// <param name="value">枚举的值</param>
        /// <returns>返回特性的值</returns>
        public static string GetDescription(this Enum value)
        {
            //获取枚举反射信息
            FieldInfo field = value.GetType().GetField(value.ToString());
            //获取枚举的特性
            DescriptionAttribute attribute = field.GetCustomAttribute<DescriptionAttribute>();
            //获取特性的值
            return attribute == null ? value.ToString() : attribute.Description;
        }
        //public static string GetMD5(this string value)
        //{
        //    return value.ToString();
        //}
    }
}
